var windowName = "fixed";
var Page
var Fixed = new List()
apiready = function(){
    onWindowShow(function () {
        getData(Page)
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        //页面数据
        tab:0,
        cat:[],
        list:[],
        en:{"id":""
            ,"name":""
            ,"category":""
            ,"buyDate":""
            ,"price":""
            ,"userBuy":""
            ,"userCheck":""
            ,"userKeep":""
            ,"status":""
        },
        open:false,
        index:0,
    },{
        //页面方法
        "init":function () {
            var _this = this;
            startPullDownRefresh();
            Fixed.setUrl("/app/fixed")
                .setCbFunc(function (data) {
                    logJson(data)
                    _this.list = data
                    stopPullDownRefresh();
                    stopPullUpLoadMore();
                }).getList()
        },
        OnPullDownRefresh:function () {
            startPullDownRefresh();
            Fixed.reload()
        },
        OnPullUpLoadMore:function () {
            if (this.tab === 0) {
                startPullUpLoadMore();
                Fixed.getList()
            }
        },
        submit:function() {
            var _this = this
            this.$refs.form.validate().then((result) => {
                if (result){
                    var form = createForm(this.en);
                    apiPost("/app/fixed/add",form,function (res) {
                        // log(res)
                        Fixed.reload()
                        _this.tab = 0
                        _this.en = clearEn(_this.en)
                        showToast(res.message)
                    })

                }else{
                    showToast("请检查输入")
                }
            });
        },
        select: function (index) {
            this.open = true
            this.index = index
        },
        del: function (index) {
            var _this = this
            var item = this.list[index]
            var data = recreateEn(item)
            this.open = false
            apiGet("/app/fixed/del",{id:data.id},function (res) {
                if (res.s == 1) {
                    getData(_this)
                    _this.list = arrayDelIndex(_this.list,index)
                }

            })
        },
        edit: function (index) {
            var _this = this
            var item = _this.list[index]
            logJson(recreateEn(item))
            _this.en = recreateEn(item)
            _this.tab = 1
            this.open = false
        },
        cancel: function () {
            this.open = false
        }
    })

    Page.init()

    function getData(_this) {
        apiGet("/app/fixed/add",{},function (res) {
            stopPullDownRefresh()
            // clearLoading()
            _this.cat = res.data.cat
            _this.en = res.data.en
        })
    }
}
